package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Arrange;
import com.ruoyi.system.service.IArrangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * arrangeController
 *
 * @author ruoyi
 * @date 2022-06-07
 */
@RestController
@RequestMapping("/system/arrange")
public class ArrangeController extends BaseController
{
    @Autowired
    private IArrangeService arrangeService;

    /**
     * 查询arrange列表
     */
    @PreAuthorize("@ss.hasPermi('system:arrange:list')")
    @GetMapping("/list")
    public TableDataInfo list(Arrange arrange)
    {
        // 判断当前登录用户角色
        if (getLoginUser().getUser().getRoleId() != 1) {
            arrange.setUserId(getUserId());
        }
        startPage();
        List<Arrange> list = arrangeService.selectArrangeList(arrange);
        return getDataTable(list);
    }

    /**
     * 导出arrange列表
     */
    @PreAuthorize("@ss.hasPermi('system:arrange:export')")
    @Log(title = "arrange", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Arrange arrange)
    {
        List<Arrange> list = arrangeService.selectArrangeList(arrange);
        ExcelUtil<Arrange> util = new ExcelUtil<Arrange>(Arrange.class);
        util.exportExcel(response, list, "arrange数据");
    }

    /**
     * 获取arrange详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:arrange:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(arrangeService.selectArrangeById(id));
    }

    /**
     * 新增arrange
     */
    @PreAuthorize("@ss.hasPermi('system:arrange:add')")
    @Log(title = "arrange", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Arrange arrange)
    {
        return toAjax(arrangeService.insertArrange(arrange));
    }

    /**
     * 修改arrange
     */
    @PreAuthorize("@ss.hasPermi('system:arrange:edit')")
    @Log(title = "arrange", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Arrange arrange)
    {
        return toAjax(arrangeService.updateArrange(arrange));
    }

    /**
     * 删除arrange
     */
    @PreAuthorize("@ss.hasPermi('system:arrange:remove')")
    @Log(title = "arrange", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(arrangeService.deleteArrangeByIds(ids));
    }
}
